package cn.lg.soar.activiti.controller;

import cn.lg.soar.activiti.dto.ModelForm;
import cn.lg.soar.activiti.service.ModelService;
import cn.lg.soar.common.model.HttpResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Map;

/**
 * @author luguoxiang
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@RestController
@RequestMapping("/model")
@Tag(description = "model", name = "model表管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class ModelController {

	private final ModelService modelService;

	public ModelController(ModelService modelService) {
		this.modelService = modelService;
	}

	@PostMapping(value = "/insert")
	@Operation(summary = "新增Model", description = "新增Model")
	public HttpResult<Boolean> insertForm(@RequestBody @Valid ModelForm form) {
		modelService.create(form.getName(), form.getKey(), form.getDesc(), form.getCategory());
		return HttpResult.data(Boolean.TRUE);
	}

	@PostMapping
	@Operation(summary = "新增Model", description = "新增Model")
	public HttpResult createModel(@RequestParam String name, @RequestParam String key, @RequestParam String desc,
			@RequestParam String category) {
		return HttpResult.data(modelService.create(name, key, desc, category));
	}

	@GetMapping
	@Operation(summary = "条件查询", description = "条件查询")
	public HttpResult getModelPage(@RequestParam Map<String, Object> params) {
		return HttpResult.data(modelService.getModelPage(params));
	}

	@DeleteMapping
	@Operation(summary = "删除模型", description = "删除模型")
	public HttpResult removeModelById(@RequestBody String[] ids) {
		return HttpResult.data(modelService.removeModelById(ids));

	}

	@PostMapping("/deploy/{id}")
	@Operation(summary = "通过id查询", description = "通过id查询")
	public HttpResult deploy(@PathVariable("id") String id) {
		return modelService.deploy(id) ? HttpResult.success() : HttpResult.fail();
	}

}
